﻿<%@ page language="java" import="java.util.*,cn.ac.cintcm.dataconverge.util.Constants,com.hs.core.utils.*" pageEncoding="UTF-8"%>
<%@ page import ="cn.ac.cintcm.dataconverge.researcher.domain.*,cn.ac.cintcm.dataconverge.researchsubject.domain.*,com.hs.core.page.PageUtil,com.hs.core.utils.StringUtilTool" %> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String imagePath = path + "/index/"; 
List userList = (List)request.getAttribute("userList");
List orgList = (List)request.getAttribute("orgList");
String achId = request.getParameter("achId");
Long  currentOrgId = -1l;
if(request.getAttribute("currentOrgId") != null)
  currentOrgId = (Long)request.getAttribute("currentOrgId");
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>DataConverge</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <script language="javascript" src="<%=path %>/index/Scripts/script.js"></script>
	<script language="javascript" src="<%=path %>/js/common.js"></script>
	<link href="<%=path %>/index/Themes/com/style.css" type="text/css" rel="stylesheet"></link>
	<script src='<%=basePath%>dwr/engine.js'></script>
     <script src='<%=basePath%>dwr/util.js'></script> 
     <script src='<%=basePath%>dwr/interface/subject.js'></script> 
    <script type="text/javascript">
      var xmlHttp;
      var url="";
      var delNode;
      //var nameArray=new Array();
    function lookMe(thisTag){
		var span = thisTag.getElementsByTagName('span')[0];
		span.style.display = 'block';
		thisTag.onmouseout = function(){
			span.style.display = 'none';
		}
	}

	function mouseMove(event){
		var xx=event.clientX + 5;
		var yy=event.clientY + 10;
		var obj = event.srcElement ? event.srcElement : event.target;
	        var span=obj.getElementsByTagName("span")[0];
		//span.style.left = xx + 'px';
		//span.style.top = yy + 'px';
	}


      function createXMLHttpRequest() {
			if (xmlHttp == null) {
	    		if (window.ActiveXObject) {
	    			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    		}
	    		else if (window.XMLHttpRequest) {
	        		xmlHttp = new XMLHttpRequest();                
	    		}
    		}
	  }
			  
      function change(){
      		var orgId=document.form0.org.value;
      		var zhicheng=document.form0.zhicheng.value;
      		var name=document.form0.name.value;
      		//alert("org id is "+orgId+" zhicheng is "+zhicheng+" name is "+name);
            url="subject.htm?action=getResearchers&orgId="+orgId+"&zhicheng="+zhicheng+"&name="+escape(name);
     	    createXMLHttpRequest();
			xmlHttp.open("GET", url, true);
    		xmlHttp.onreadystatechange = callback;
    		xmlHttp.send(null);
      }  
      function callback(){
      	if(xmlHttp.readyState==4){
    			if(xmlHttp.status==200){
    				clearResults();
    				parseMessage();
    			}
    		}
      }
      function researchersObj(){
         var dept = '&nbsp;';
         var zhicheng = '&nbsp;';
		 var major = '&nbsp;';
      }
      function parseMessage(){
      		var xmlDoc = xmlHttp.responseXML;
			var nodes = xmlDoc.getElementsByTagName('researcher');
			var res=document.getElementById("researchers");
			if(nodes!=null){
				var id="";
				var name="";
				var detail="";
				var tr;
				for(var i=0;i<nodes.length;i++){
					//id=nodes[i].firstChild.firstChild.nodeValue;
					//name=nodes[i].nextChild.firstChild.nodeValue;
					//detail=nodes[i].lastChild.firstChild.nodeValue;
					id=nodes[i].getElementsByTagName("id")[0].firstChild.nodeValue;
					name=nodes[i].getElementsByTagName("name")[0].firstChild.nodeValue;
					detail=nodes[i].getElementsByTagName("detail")[0].firstChild.nodeValue;
					var resObj =new researchersObj();
					if(nodes[i].getElementsByTagName("dept")[0].firstChild != null)
						resObj.dept = nodes[i].getElementsByTagName("dept")[0].firstChild.nodeValue;
					else resObj.dept="";
					if(nodes[i].getElementsByTagName("zhicheng")[0].firstChild != null)
						resObj.zhicheng = nodes[i].getElementsByTagName("zhicheng")[0].firstChild.nodeValue;
					else resObj.zhicheng="";
					if(nodes[i].getElementsByTagName("major")[0].firstChild != null)
						resObj.major = nodes[i].getElementsByTagName("major")[0].firstChild.nodeValue;
						else resObj.major="";
					if(i%12==0){
						tr = res.insertRow(res.rows.length);
					}
					
					addResN(id,name,detail,tr,resObj);					
					//addRes(id,name);
				
				}
			}			
      }
      function researcherChick(id){
	      if(id==null)
	      return ;
	      var cid =document.getElementById("researcher-"+id);
	      if(cid != null)
	      	if(cid.checked)cid.checked = false;
	      		else cid.checked = true;
      }
      function addResN(id,name,detail,parentNode,resObj){
      	var td= parentNode.insertCell();
      	td.innerHTML=
      	'<div onmouseover="lookMe(this);" class="lookMe" onmousemove="mouseMove(event);">'+
      	'<input type="checkbox" name="researcher" id="researcher-'+id+'" value="'+id+'"><font style="cursor: hand" onclick="researcherChick('+id+');">'+name+'</font>'+
      	'<span>'+
      	'姓名:'+name+
      	'<br>部门:'+resObj.dept+
      	'<br>职称:'+getZhicheng(resObj.zhicheng)+
      	'<br>专业:'+resObj.major+
      	'</span>'+
      	'</div>'; 
      }
      function getZhicheng(zhicheng){
         if("1" == zhicheng)
            return "正高";
         if("2" == zhicheng)
            return "副高";
         if("3" == zhicheng)
            return "中级";
         if("4" == zhicheng)
            return "初级";
         if("5" == zhicheng)
            return "其它"; 
         if("undefined" == zhicheng)
           return "";
      }
    
      function clearResults(){
         	var res=document.getElementById("researchers");
         	while(res.childNodes.length > 0) {
				res.removeChild(res.childNodes[0]);
			}
      } 
      function checkSeq(seq){
      	var exp = new RegExp("^[0-9]{1,4}$");
      	if(isNull(seq)){
      	 	alert("请输入顺序号");
      	}  
      	 if(seq!="" && !exp.test(seq)){
      		alert("请输入有效的顺序号，顺序号必须是整数");
      		return false;
      	}
      	return true;
      }
      var achId='<%=achId%>';
      
        function refresh(){
                window.location.replace(document.location.href);
        } 
        
        function addAchRes(){ 
	        var researcherIds="";
	        var trs=document.getElementsByName("researcher");
			for(var i=0;i<trs.length;i++){
					var checkb=trs[i];
					if(checkb.checked){
						researcherIds += checkb.value+",";
					}
			}
			if(researcherIds==""){
				alert("请选择至少一个科研人员");
				return;
			}
			var role = form0.role.value;
            subject.addAchUser(achId,researcherIds,role,addCallBack);
        }
        function addCallBack(data){
           alert("操作成功");
           refresh();
        }
        
        function delSubRes(subResId){
          if(confirm("确认要删除该人员吗？"))
              subject.deleteAchUser(subResId,callbackForDelSubRes);
        }
      
      function callbackForDelSubRes(data){
         alert("操作成功");
      	    
         window.location.replace(window.location.href);
      }  
      function chgOrd(subResId){
      
        if(!confirm("需要更改此科研人员的序号吗？"))	
            return; 
        var name= 'resord'+subResId;
        var ord=document.getElementById(name).value;
        
        if (checkSeq(ord)) {
       	   subject.updateSeq(subResId,ord,callbackChgResOrd);
       	}
       }
      
        function callbackChgResOrd(){
      	     alert("操作成功");
      	      window.location.replace(window.location.href);
    	} 
    	function changeTop(){
         var obj = parent.frames("bannerFrame"); 
         obj.location.href="<%=path%>/achieve.htm?action=top&modId=5&achId=<%=achId %>";
    }
    </script>
    <style type="text/css">
.lookMe{
	color:#0099FF;
	cursor:pointer;
}
.lookMe span{
	display:none;
	position:absolute;
	/*left:50px;
	top:20px;*/
	padding:5px;
	width:200px;
	z-index:10000000000;
	color:#CC3300;
	background:#FFFADC;
	border:1px solid #CC6600;
}
</style>
  </head>
  <body class="rtm_body" onload="change();">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td>
                <div class="content">
                    <table width="*" cellpadding="0"  cellspacing="1" class="dg_borderstyle" id="Table4">
                        <tr>
                            <td class="dg_headerstyle" width="15%">
                               	序号</td>
                            <td class="dg_headerstyle" width="20%">
                                 姓名</td>
                            <td class="dg_headerstyle" width="35%">
                                 职称</td> 
                            <td class="dg_headerstyle">
                                删除</td> <% //如果课题状态为1 那么不允许删除 稍后完善  %>
                        </tr>
                        <% 
                         
                        if(null != userList && userList.size()>0){ 
	                        Iterator iterator = userList.iterator(); 
	                        int i =1;
	                        while(iterator.hasNext()){
	                        	 Map map = (Map)iterator.next();
	                        %>
	                        <tr class="dg_alternatingitemstyle">
	                            <td> <input type="text" id="resord<%=map.get("PID")%>" class="com_textbox" size="5" value ="<%=map.get("SEQUENCE") %>"/>
	                         <a href="#"  onclick="chgOrd('<%=map.get("PID") %>');">改变序号</a></td>
	                            <td>
	                                <%=map.get("NAME") %>
	                            </td>
	                            <td>
	                                 <%
	                                 if(Constants.researcher_zhenggao.equals(map.get("ZHICHENG")+""))
	                                     out.println("正高");
	                                  if(Constants.researcher_fugao.equals(map.get("ZHICHENG")+""))
	                                     out.println("副高");
	                                  if(Constants.researcher_zhongji.equals(map.get("ZHICHENG")+""))
	                                     out.println("中级");
	                                  if(Constants.researcher_diji.equals(map.get("ZHICHENG")+""))
	                                     out.println("初级");
	                                   if(Constants.researcher_zhich_others.equals(map.get("ZHICHENG")+""))
	                                     out.println("其它"); %>
	                            </td> 
	                            <td align="center">
	                                <img style="cursor:hand" src="<%=imagePath %>Themes/com/68design.net_registration1_(delete)_16x16.gif" onclick="javaScript:delSubRes(<%=map.get("PID") %>);"
	                                    alt="删除" />
	                            </td> 
	                        </tr> 
                        <%}}else{ %>
                          <tr class="dg_alternatingitemstyle"> 
                            <td align="center" colspan=4>
                                <font color="red">没有找到记录</font>
                            </td> 
                        </tr>  
                        <%} %>
                    </table>  
                </div>
            </td>
        </tr>
    </table>
  
	
 <table cellpadding="0" cellspacing="0" width="100%" height="100%" id="Table8">
 <form name="form0">
     	<input type="hidden" name="subjectId" value="${subjectId}"/>
        <tr>
            <td valign="top" height="100%">
                <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" id="Table11">
                    <tr>
                        <td valign="top" >
                            <!------------------ 标题栏 ------------------>
                            <!--- 标题 ---->
                            <table class="idt_tle_mg" cellspacing="0" cellpadding="0" width="100%">
                                <tr >
                                    <td class="idt_tle_i">
                                        <img id="imgForm6" src="<%=basePath%>index/Themes/com/idt_tle_o.gif"></td>
                                    <td class="idt_tle_f1">
                                        添加成果人员</td>
                                </tr>
                            </table>
                            <!--- 内容 --->
                            <div id="tdForm">
                                <table border="0" cellpadding="0" cellspacing="1" width="100%" class="idt_fim_mg">
                                    <tr>
                                        <td class="fim_l" width="15%">
                                           所在单位</td>
                                        <td class="fim_r" width="35%">
	                                        <select name="org"  onchange="change();"  style="width:100%"> 
				    					<%   
				    					     Iterator iterator02 = orgList.iterator();
					    					 while(iterator02.hasNext()){
					    					 	Organization org = (Organization)iterator02.next();
					    					 	Long key = org.getId();
				    					 %> 
				    					 	<option value="<%=key %>" <%if(key == currentOrgId)out.print("selected"); %>><%=org.getName() %></option>
				    					 <%} %>
				    			    </select>
                                        </td>
                                         <td class="fim_l" width="15%">
                                           职称</td>
                                        <td class="fim_r" >
	                                       <select name="zhicheng" onchange="change();" style="width:80%">
												<option value="0">-------请选择--------</option>
												<option value="1">正高</option>
												<option value="2">副高</option>
												<option value="3">中级</option>
												<option value="4">初级</option>
												<option value="5">其它</option>
											</select>
                                            </td>
                                    </tr>
                                    <tr>
                                        <td class="fim_l" width="15%">
                                          姓名</td>
                                        <td class="fim_r"  id="departments" colspan="3" >
                                       		<input type="text" name="name" class="com_textbox" style="width:40%" onkeyup="change();">&nbsp;&nbsp; <font color=red><b>注：输入姓名，可在以下列表中查询科研人员</b></font>
                                         </td>
                                    </tr>
                                    <tr>
                                        <td class="fim_l">备选人</td>
                                        <td class="fim_r" colspan="3">
	                                       <TABLE id="researchers">
	                                       </TABLE>
                                            </td>
                                      </tr>
                                      <tr>
                                        <td class="fim_l">
                                            人员角色</td>
                                        <td  class="fim_r" colspan="3">
                                           <select name="role"><option value="负责人">负责人</option><option value="参与人员">参与人员</option></select>
 											 
                                        <input type="button" value="添加到成果"  class="com_textbox"  onclick="addAchRes();">
                                           </td>
                                    </tr>
                                </table>
                                 <table cellspacing="0" cellpadding="0" width="100%" class="idt_bottom_mg" border="0">
                                    <tr>
                                        <td align="center">
                                           <!--  <input  class="com_btn2" id="Button1"  onclick="" type="button"   value="上一步">
                                            &nbsp; &nbsp;
                                             <input  class="com_btn2" id="Button1"  onclick="" type="button" value="下一步">-->
                                        </td>
                                    </tr>
                                </table>
                            </div>
                </table></form>
  </body>
</html>
<script>
changeTop();

</script>